function table_2 = testTotal(option_test, market_code, number_of_stocks, stock_codes, porfolio_weights, ...
                            risk_free, cost, short_MA_length, long_MA_length, band, test_option)
    
    %option_test = 'index';
    %option_test = 'portfolio';

    switch option_test
        case 'index'
            if (isempty(market_code))
                market_code = getRandomMarketCode();
            end
            [codes date close_price volume] = getIndex(cell2mat(market_code));
        case 'portfolio'
            [codes weights_p date close_price_p volume_p] = getPortfolio(market_code, number_of_stocks, stock_codes, porfolio_weights);
            close_price = close_price_p(:, 2:end) * weights_p;
        otherwise
    end
    
    %r_price = log(close_price(2:end)./close_price(1:end-1));
    
    %short_MA_length = 5;
    %long_MA_length  = 100;
    %band = 0.05;
    
    %testVLMA_option = 's';
    %testVLMA_option = 'e';
    
    n_short_MA_length = length(short_MA_length);
    n_long_MA_length  = length(long_MA_length);
    n_band            = length(band);
    
    table_1 = [{'Table 1: Summary statistics for daily and 10-day returns', [], [], [], [], [], [], [], [], [], [], []};...
                {'Panel', 'Sample size (n)', 'Mean', 'Std. deviation', ...
                'Skewness', 'Kurtosis', 'pro(1)', 'pro(2)', 'pro(3)', 'pro(4)', 'pro(5)', 'Barlett std.'}];
    table_2 = [{'Table 2: Standard results for the variable-length moving (VMA) rules', [], [], [], [], [], [], [], [], [], []};...
                {'Period', 'Short MA length', 'Long MA length', 'Band', ...
                'N(Buy)', 'N(Sell)', 'Buy', 'Sell', 'Buy > 0', 'Sell > 0', 'Buy - Sell'}];
    table_3 = [{'Table 3: Standard results for the fixed-length moving (FMA) rules', [], [], [], [], [], [], [], [], [], []};...
                {'Period', 'Short MA length', 'Long MA length', 'Band', ...
                'N(Buy)', 'N(Sell)', 'Buy', 'Sell', 'Buy > 0', 'Sell > 0', 'Buy - Sell'}];
    table_4 = [{'Table 4: Standard results for the trading range break (TRB) rules', [], [], [], [], [], [], [], [], [], []};...
                {'Period', 'Short MA length', 'Long MA length', 'Band', ...
                'N(Buy)', 'N(Sell)', 'Buy', 'Sell', 'Buy > 0', 'Sell > 0', 'Buy - Sell'}];
    table_5 = [{'Table 5: Parameters estimates for the AR(1), GARCH(1,1) and GARCH(1,1)-M models', [], [], [], [], [], [], []};...
                {'Period', 'Panel', 'delta', 'pro', 'w', 'alpha', 'beta', 'leverage'}];
    table_6 = [{'Table 6 : Simulation tests from AR(1) bootstraps for 500 replications', [], [], [], [], [], [], [], [], []}; ...
               {'Panel A: Individual rules', [], [], [], [], [], [], [], [], []}; ...
               {'Rule', [], [], [], 'Result', 'Buy', 'sigma_b', 'Sell', 'sigma_s', 'Buy-Sell'}];
    table_7 = [{'Table 7 : Simulation tests from GARCH(1,1) bootstraps for 500 replications', [], [], [], [], [], [], [], [], []}; ...
               {'Panel A: Individual rules', [], [], [], [], [], [], [], [], []}; ...
               {'Rule', [], [], [], 'Result', 'Buy', 'sigma_b', 'Sell', 'sigma_s', 'Buy-Sell'}];
    table_8 = [{'Table 8 : Simulation tests from E-GARCH(1,1) bootstraps for 500 replications', [], [], [], [], [], [], [], [], []}; ...
               {'Panel A: Individual rules', [], [], [], [], [], [], [], [], []}; ...
               {'Rule', [], [], [], 'Result', 'Buy', 'sigma_b', 'Sell', 'sigma_s', 'Buy-Sell'}];
           
    [N Mean Std Skewness Kurtosis Rho] = Statistic(close_price,1);
    table_1 = [table_1; {'Panel A: Dailyreturns', N, Mean, Std, Skewness, Kurtosis, Rho(2), Rho(3), Rho(4), Rho(5), Rho(6), []}];
    [N Mean Std Skewness Kurtosis Rho] = Statistic(close_price,10);
    table_1 = [table_1; {'Panel B: 10-day returns', N, Mean, Std, Skewness, Kurtosis, Rho(2), Rho(3), Rho(4), Rho(5), Rho(6), []}];
    
     for i = 1:n_short_MA_length
         for j = 1:n_long_MA_length
             for k = 1:n_band
                
                 % Table 2 => Okay
                [r_VMA, rBuy_VMA, rSell_VMA] = testVLMA(close_price, risk_free, cost, short_MA_length(i), long_MA_length(j), band(k), test_option,[]);
                  
                [t_test_results_VMA t_test_p_values_VMA t_test_t_stat_VMA...
                    nBuy_VMA nSell_VMA mBuy_VMA mSell_VMA diffBS_VMA fractionB_VMA fractionS_VMA]...
                    = testMATTest(rBuy_VMA, rSell_VMA, r_VMA);
                  
                table_2 = [table_2; {[], short_MA_length(i), long_MA_length(j), band(k),...
                            nBuy_VMA, nSell_VMA, mBuy_VMA, mSell_VMA, fractionB_VMA, fractionS_VMA, diffBS_VMA}]; 
                table_2 = [table_2; {[], [], [], [],...
                            [], [], t_test_t_stat_VMA(1), t_test_t_stat_VMA(2), [], [], t_test_t_stat_VMA(3)}]; 
                    
                 % Table 3 => Okay
                [r_FMA, rBuy_FMA, rSell_FMA] = testFLMA(close_price, risk_free, cost, short_MA_length(i), long_MA_length(j), band(k), test_option, []);
                  
                [t_test_results_FMA t_test_p_values_FMA t_test_t_stat_FMA...
                    nBuy_FMA nSell_FMA mBuy_FMA mSell_FMA diffBS_FMA fractionB_FMA fractionS_FMA]...
                    = testMATTest(rBuy_FMA, rSell_FMA, r_FMA);
                  
                table_3 = [table_3; {[], short_MA_length(i), long_MA_length(j), band(k),...
                            nBuy_FMA, nSell_FMA, mBuy_FMA, mSell_FMA, fractionB_FMA, fractionS_FMA, diffBS_FMA}]; 
                table_3 = [table_3; {[], [], [], [],...
                            [], [], t_test_t_stat_FMA(1), t_test_t_stat_FMA(2), [], [], t_test_t_stat_FMA(3)}];                         
                          
                        
                % Test bootstrap
            
                 [ARparameters_VMA ARparaTStat_VMA ARfractions_VMA GARparameters_VMA GARparaTStat_VMA GARfractions_VMA...
                     EGARparameters_VMA EGARparaTStat_VMA EGARfractions_VMA]...
                         = testMABootstrap(close_price, risk_free, cost, short_MA_length(i), long_MA_length(j), band(k), test_option, [], 'V');
                 [ARparameters_FMA ARparaTStat_FMA ARfractions_FMA GARparameters_FMA GARparaTStat_FMA GARfractions_FMA...
                     EGARparameters_FMA EGARparaTStat_FMA EGARfractions_FMA]...
                         = testMABootstrap(close_price, risk_free, cost, short_MA_length(i), long_MA_length(j), band(k), test_option, [], 'F');                    
                 [ARparameters_TRB ARparaTStat_TRB ARfractions_TRB GARparameters_TRB GARparaTStat_TRB GARfractions_TRB...
                     EGARparameters_TRB EGARparaTStat_TRB EGARfractions_TRB]...
                         = testMABootstrap(close_price, risk_free, cost, [], [], band(k), test_option, long_MA_length(j), 'T');                    
                 
                % Table 6
                table_6 = [table_6; {short_MA_length(i), long_MA_length(j), band(k), 'VMA', 'Fraction > ...', ...
                                    ARfractions_VMA(1), ARfractions_VMA(4), ARfractions_VMA(2), ARfractions_VMA(5), ARfractions_VMA(3)}];
                table_6 = [table_6; {[], [], [], 'FMA', 'Fraction > ...', ...
                                    ARfractions_FMA(1), ARfractions_FMA(4), ARfractions_FMA(2), ARfractions_FMA(5), ARfractions_FMA(3)}];
                table_6 = [table_6; {[], [], [], 'TRB', 'Fraction > ...', ...
                                    ARfractions_TRB(1), ARfractions_TRB(4), ARfractions_TRB(2), ARfractions_TRB(5), ARfractions_TRB(3)}];
                
                % Table 7
                table_7 = [table_7; {short_MA_length(i), long_MA_length(j), band(k), 'VMA', 'Fraction > ...', ...
                                    GARfractions_VMA(1), GARfractions_VMA(4), GARfractions_VMA(2), GARfractions_VMA(5), GARfractions_VMA(3)}];
                table_7 = [table_7; {[], [], [], 'FMA', 'Fraction > ...', ...
                                    GARfractions_FMA(1), GARfractions_FMA(4), GARfractions_FMA(2), GARfractions_FMA(5), GARfractions_FMA(3)}];
                table_7 = [table_7; {[], [], [], 'TRB', 'Fraction > ...', ...
                                    GARfractions_TRB(1), GARfractions_TRB(4), GARfractions_TRB(2), GARfractions_TRB(5), GARfractions_TRB(3)}];
                
                % Table 8
                table_8 = [table_8; {short_MA_length(i), long_MA_length(j), band(k), 'VMA', 'Fraction > ...', ...
                                    EGARfractions_VMA(1), EGARfractions_VMA(4), EGARfractions_VMA(2), EGARfractions_VMA(5), EGARfractions_VMA(3)}];
                table_8 = [table_8; {[], [], [], 'FMA', 'Fraction > ...', ...
                                    EGARfractions_FMA(1), EGARfractions_FMA(4), EGARfractions_FMA(2), EGARfractions_FMA(5), EGARfractions_FMA(3)}];
                table_8 = [table_8; {[], [], [], 'TRB', 'Fraction > ...', ...
                                     EGARfractions_TRB(1), EGARfractions_TRB(4), EGARfractions_TRB(2), EGARfractions_TRB(5), EGARfractions_FMA(3)}];
                
             end
         end
     end
     
     % Table 4 => Okay
     for i = 1:n_long_MA_length
         for j = 1:n_band
             [r_TRB, rBuy_TRB, rSell_TRB] = testTRB(close_price, risk_free, cost, [], [], band(j), test_option, long_MA_length(i));
                 
             [t_test_results_TRB t_test_p_values_TRB t_test_t_stat_TRB...
                   nBuy_TRB nSell_TRB mBuy_TRB mSell_TRB diffBS_TRB fractionB_TRB fractionS_TRB]...
                   = testMATTest(rBuy_TRB, rSell_TRB, r_TRB);
                  
             table_4 = [table_4; {[], 1, long_MA_length(i), band(j),...
                        nBuy_TRB, nSell_TRB, mBuy_TRB, mSell_TRB, fractionB_TRB, fractionS_TRB, diffBS_TRB}]; 
             table_4 = [table_4; {[], [], [], [],...
                        [], [], t_test_t_stat_TRB(1), t_test_t_stat_TRB(2), [], [], t_test_t_stat_TRB(3)}];        
         end
     end
     
      % Table 5 
    table_5 = [table_5; {[], 'Panel A: AR(1) parameters estimate', ...
                         ARparameters_VMA(1), ARparameters_VMA(2),      '-',    '-',                            '-', '-'}];
    table_5 = [table_5; {[], [], ...
                        ARparaTStat_VMA(1),  ARparaTStat_VMA(2),      '-',    '-',                            '-', '-'}];
    table_5 = [table_5; {[], 'Panel B: GARCH(1,1) parameters estimate', ...
                         GARparameters_VMA(1), GARparameters_VMA(2), GARparameters_VMA(3), GARparameters_VMA(5), GARparameters_VMA(4), '-'}];
    table_5 = [table_5; {[], [], ...
                        GARparaTStat_VMA(1),  GARparaTStat_VMA(2), GARparaTStat_VMA(3),  GARparaTStat_VMA(5),  GARparaTStat_VMA(4), '-'}];
    table_5 = [table_5; {[], 'Panel C: GARCH(1,1)-M parameters estimate', ...
                         EGARparameters_VMA(1), EGARparameters_VMA(2), EGARparameters_VMA(3), ...
                         EGARparameters_VMA(5), EGARparameters_VMA(4), EGARparameters_VMA(6)}];
    table_5 = [table_5; {[], [], ...
                        EGARparaTStat_VMA(1), EGARparaTStat_VMA(2), EGARparaTStat_VMA(3), EGARparaTStat_VMA(5),... 
                        EGARparaTStat_VMA(4), EGARparaTStat_VMA(6)}];
     
    xlswrite('TestingResult.xls', table_1, 'Table_1');
    xlswrite('TestingResult.xls', table_2, 'Table_2');
    xlswrite('TestingResult.xls', table_3, 'Table_3');
    xlswrite('TestingResult.xls', table_4, 'Table_4');
    xlswrite('TestingResult.xls', table_5, 'Table_5');
    xlswrite('TestingResult.xls', table_6, 'Table_6');
    xlswrite('TestingResult.xls', table_7, 'Table_7');
    xlswrite('TestingResult.xls', table_8, 'Table_8');
                                                        
end